<template>
	<view>
		<view class="input-container" style="margin-top: 20rpx;" v-if="zhuangtai!=''">
			<view class="uni-row input-item">
				<view class="input-name">昵称</view>
				<view class="input"><input type="text"  v-model="nickname" placeholder="请填写昵称" placeholder-style="font-size:28rpx;color:#999999" /></view>
			</view>
		</view>
		<button class="big-btn" @tap="save()">保存</button>
	</view>
	
</template>

<script>
	import {getlogin} from "@/static/js/login.js";
	import httpPath from '@/static/js/path.js';
	export default {
			data() {
				return {
					wxinfo_id:"",
					userinfo:{},
					nickname:"",
				}
			},
			onLoad(option) {
				this.userinfo = getlogin()
				this.wxinfo_id = this.userinfo.wxinfo_id;
	            this.nickname=this.userinfo.nickname;
			},
			methods: {
				save(){
					if(!this.nickname){
						uni.showModal({
							showCancel:false,
							content:"请填写昵称"
						})
						return false;
					}
					uni.request({
						url: httpPath.filePath+'/index/wxinfo/nickname',
						method:'POST',
						header:{'content-type':'application/x-www-form-urlencoded'},
						data: {wxinfo_id:this.wxinfo_id,nickname:this.nickname},
						success: (res) => {
							if(res.data.code==200){
								this.userinfo.nickname = res.data.data.nickname;
								uni.setStorage({
								    key: 'user',
								    data: this.userinfo,
								    success: function () {
								        uni.navigateBack()
								    }
								});
							}
							   
						}
					});
				}
			}
		}
</script>

<style>
	.big-btn{position: fixed;bottom: 150rpx;left: calc(50% - 265rpx);}
</style>
